﻿<DemoContainer>
    <ApexChart TItem="Order"
               Title="Order Net Value"
               Options=options>

        <ApexPointSeries TItem="Order"
                         Items="Orders"
                         Name="Value"
                         XValue="@(e => e.Country)"
                         YAggregate="@(e => e.Sum(e => e.GrossValue))"
                         SeriesType="SeriesType.Bar" />

        <ApexPointSeries TItem="Order"
                         Items="Orders"
                         Name="NetValue"
                         XValue="@(e => e.Country)"
                         YAggregate="@(e => e.Sum(e => e.NetValue))"
                         SeriesType="SeriesType.Bar" />

        <ApexPointSeries TItem="Order"
                         Items="Orders"
                         Name="Discount"
                         XValue="@(e => e.Country)"
                         YAggregate="@(e => e.Average(e => e.DiscountPercentage))"
                         SeriesType="SeriesType.Line" />
    </ApexChart>
</DemoContainer>

@code {
    private List<Order> Orders { get; set; } = SampleData.GetOrders();
    private ApexChartOptions<Order> options { get; set; } = new();

    protected override void OnInitialized()
    {
        options.Yaxis = new List<YAxis>();

        options.Yaxis.Add(new YAxis
            {
                Title = new AxisTitle { Text = "Value" },
                SeriesName = "Value",
                DecimalsInFloat = 0
            });
        options.Yaxis.Add(new YAxis
            {
                Show = false,
                SeriesName = "NetValue",
                DecimalsInFloat = 0
            });
        options.Yaxis.Add(new YAxis
            {
                Title = new AxisTitle { Text = "Percentage" },
                SeriesName = "Discount",
                DecimalsInFloat = 0,
                Opposite = true
            });
    }

}
